package com.vhall.component.plugin.common.utils;


import org.apache.commons.lang3.StringUtils;

/**
 * @Author: xin.qin
 * @Date: 2022/06/23 14:12
 */
public class ShadingUtil {
    private static final String STAR = "*";

    /**
     * 姓名遮盖
     *
     * @param s
     * @return
     */
    public static String shadingName(String s) {
        return StringUtils.isNotBlank(s) && s.length() > 0 ? times(1) + s.substring(1) : s;
    }


    /**
     * 手机号遮盖
     *
     * @param s
     * @return
     */
    public static String shadingPhone(String s) {
        return StringUtils.isNotBlank(s) && s.length() == 11 ? s.substring(0, 3) + times(4) + s.substring(7) : s;
    }

    /**
     * 身份证遮盖
     *
     * @param s
     * @return
     */
    public static String shadingIDCard(String s) {
        return StringUtils.isNotBlank(s) && s.length() == 18 ? s.substring(0, 2) + times(14) + s.substring(16) : s;
    }


    /**
     * 银行卡遮盖
     *
     * @param s
     * @return
     */
    public static String shadingBankNo(String s) {
        return StringUtils.isNotBlank(s) && s.length() > 4 ? times(10) + s.substring(s.length() - 4) : s;
    }

    private static String times(int times) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < times; i++) {
            sb.append(STAR);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(shadingName("诸葛亮"));
        System.out.println(shadingPhone("18810098789"));
        System.out.println(shadingIDCard("130728198810091515"));
        System.out.println(shadingBankNo("110101198311132515"));
    }

}
